package com.hehua.ObserverPattern;

import java.util.ArrayList;

/**
 * 指挥部充当抽象目标类
 */
public abstract class AllyControlCenter {
    /**
     * 战队名称
     */
    protected String allyName;
    /**
     * 定义一个集合用于存储作战成员
     */
    protected ArrayList<Observer> plays = new ArrayList<Observer>();


    public String getAllyName() {
        return allyName;
    }

    public void setAllyName(String allyName) {
        this.allyName = allyName;
    }

    /**
     * 注册方法
     * @param obs
     */
    public void join(Observer obs){
        System.out.println(obs.getName()+"加入"+this.getAllyName()+"战队");
        plays.add(obs);
    }

    public void quit(Observer obs){
        System.out.println(obs.getName()+"退出"+this.getAllyName()+"战队");
        plays.remove(obs);
    }

    /**
     * 声明抽象方法
     * @param name
     */
    public abstract void notifyObserver(String name);

}
